import 'package:get/get.dart';
import 'package:xin_he/page/mine/xin_he_mine_withdraw/xin_he_mine_withdraw_records/xin_he_withdraw_model_entity.dart';

import '../../../../service/xin_he_reqest.dart';
import '../../../../utils/xin_he_storage.dart';
import '../../../../utils/xin_he_toast.dart';
import '../../xin_he_mine_cloud_cha_zi/xin_he_assets_account_list_item_entity.dart';
import 'xin_he_mine_withdraw_records_state.dart';

class XinHeMineWithdrawRecordsLogic extends GetxController {
  final XinHeMineWithdrawRecordsState state = XinHeMineWithdrawRecordsState();
  RxList dataList = [].obs;


  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    state.currentDate.value = getYearMonth(DateTime.now());

    requestWithdrawRecords();
  }



  getYearMonth(DateTime date){

    return '${date.year}年${date.month}月';
  }


  requestWithdrawRecords() async{


    var userId = await XinHeLocalStorage.get(XinHeStorage.userId);
    Map<String,dynamic> ss = {
    'userId':userId,
    };

    XinHeRequestDataResult result = await XinHeHttpRequestData.requestUniversalPost(url: '/withdrawalsRecord/queryUserWithdrawalsRecord',params: ss,isPost: false);
    if(!result.result || result.data['code'] != 0) {
    XinHeToast.center(result.data['message']);
    return ;
    }
    List list = result.data['data']??[];
    List modelArr = [];
    if(list.isNotEmpty) {
      for(var e in list) {
        XinHeWithdrawModelEntity model = XinHeWithdrawModelEntity.fromJson(e);
        modelArr.add(model);
      }
      dataList.value = modelArr;
    }
  }
}
